package com.yk.silence.rxmvp.net.file;

import com.yk.silence.rxmvp.base.BaseObserver;
import com.yk.silence.rxmvp.base.BaseView;

import java.io.File;

public abstract class FileObserver extends BaseObserver<String> {

    DownLoadFileView mView;

    public FileObserver(DownLoadFileView mView) {
        super(mView);
        this.mView=mView;
    }

    @Override
    protected void onStart() {
        super.onStart();
        if (mView != null) {
            mView.showLoadingFileDialog();
        }
    }

    @Override
    public void onComplete() {
        super.onComplete();
        if (mView != null) {
            mView.hideLoadingFileDialog();
        }
    }

    @Override
    public void onNext(String s) {
        super.onNext(s);
        File file = new File(s);
        if (file != null && file.exists()) {
            onSuccess(file);
        } else {
            onFailed("file is null or a file does not exist");
        }
    }

    @Override
    public void onSuccess(String s) {

    }

    @Override
    public void onError(String msg) {

    }

    /**
     * 成功
     *
     * @param file
     */
    public abstract void onSuccess(File file);

    /**
     * 失败
     *
     * @param msg
     */
    public abstract void onFailed(String msg);
}
